<template>
	<view>
		<scroll-view scroll-y class="page">
			<!-- 头部 -->
			<cu-custom bgColor="bg-rgb" :isBack="true">
				<block slot="backText">返回</block>
				<block slot="content">点检</block>
			</cu-custom>
			<!-- 数据列表 -->
			<view class="list">
				<form>
					<view class="card animation-slide-bottom">
						<view class="bottom">
							<view class="box">
								<view class="lable">
									设备名称:
								</view>
								<view class="content">
									{{objMsg.deviceName}}
								</view>
							</view>
							<view class="box">
								<view class="lable">
									设备型号:
								</view>
								<view class="content">
									{{objMsg.deviceModel}}
								</view>
							</view>
							<view class="box">
								<view class="lable">
									点检类型:
								</view>
								<view class="content">
									<picker range-key="itemText" @change="kwChange" value="itemValue"
										:range="checkTypeList">
										<view class="picker">
											{{checkTypeList[index]}}
										</view>
									</picker>
								</view>
							</view>
							<view class="box">
								<view class="lable">
									{{index === 1 ? '清洁时间' : '班别'}}:
								</view>
								<view class="content">
									<picker range-key="type" @change="kwChange2" value="value"
										:range="resultList">
										<view class="picker">
											{{resultList[index2].type}}
										</view>
									</picker>
								</view>
							</view>
							<view v-for="(item,indexs) in checkList" :key="indexs" v-if="!loadding && index != 1">
								<view class="line"></view>
								<view class="box">
									<view class="lable">
										确认项目:
									</view>
									<view class="content">
										{{item.inspectionItems}}
									</view>
								</view>
								<view class="box">
									<view class="lable">
										确认结果:
									</view>
									<view class="content">
										<input :placeholder="'请输入确认结果'" style="text-align: right;"
											name="input" v-model="item.inspectionResults"></input>
									</view>
								</view>
							</view>
							<view class="line"></view>
							<view class="box">
								<view class="lable">
									操作员:
								</view>
								<view class="content">
									<input placeholder="请输入操作员" v-model="maintainer"></input>
								</view>
							</view>
							<view class="box">
								<view class="lable">
									主管:
								</view>
								<view class="content">
									<input placeholder="请输入主管" v-model="reviewer"></input>
								</view>
							</view>
						</view>
						<view class="line"></view>
						<view class="btns" v-if="!loadding">
							<button @click="onSubmit" class="cu-btn bg-rgb shadow lg">保存</button>
						</view>
					</view>
				</form>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		name: 'shelvesGoods',
		data() {
			return {
				loadding: true,
				myFormData: {
					goodsId: '',
					barcode: ''
				},
				objMsg: {}, // 上架单列表
				checkTypeList: [],
				index2:0,
				resultList: [
					{
						type: '白班',
						value: '白班',
					},
					{
						type: '夜班',
						value: '夜班',
					}
				],
				classList:[
					{
						type: '白班',
						value: '白班',
					},
					{
						type: '夜班',
						value: '夜班',
					}
				],
				timeList:[
					{type: '8:00',value: '8:00'},
					{type: '10:00',value: '10:00'},
					{type: '12:00',value: '12:00'},
					{type: '14:00',value: '14:00'},
					{type: '16:00',value: '16:00'},
					{type: '18:00',value: '18:00'},
					{type: '20:00',value: '20:00'},
					{type: '22:00',value: '22:00'},
					{type: '0:00',value: '0:00'},
					{type: '2:00',value: '2:00'},
					{type: '4:00',value: '4:00'},
					{type: '6:00',value: '6:00'},
				],
				index: 0,
				checkList: [],
				ironList: [],
				measure: {
					'0': '√',
					'1': '×',
					'2': '—',
				},
				maintainer: "",
				reviewer: "",
			}
		},
		onLoad(option) {
			this.objMsg = this.$Route.query.objMsg
			this.getCheckType()
		},
		methods: {
			getCheckType() {
				this.$http.get('produce/mesMaintenanceRecordMain/queryProjectModeByCode', {
						params: {
							tableNameCode: this.objMsg.query1
						}
					})
					.then(res => {
						if (res.data.success) {
							this.checkTypeList = res.data.result
							this.getCheckList()
						} else {
							this.modal.show({
								type: 'error',
								content: res.data.message
							})
						}
					})
			},
			getCheckList() {
				this.loadding = true
				this.$http.get('produce/mesMaintenanceRecordMain/queryProjectModeByCodeAndProject', {
					params: {
						tableNameCode: this.objMsg.query1,
						project: this.checkTypeList[this.index]
					}
				}).then(res => {
					if (res.data.success) {
						let arr = []
						this.checkList = []
						res.data.result.forEach(item => {
							arr.push({
								inspectionItems: item,
								inspectionResults: '',
							})
						})
						this.checkList = arr
						this.loadding = false
						console.log(111, this.checkList)
					} else {
						this.modal.show({
							type: 'error',
							content: res.data.message
						})
					}
				})
			},
			radioChange(e, index) {
				this.checkList[index].inspectionResults = e.target.value
			},
			kwChange(e) {
				this.index = e.target.value
				this.index2 = 0
				if(this.index === 1){
					this.resultList = this.timeList
				}else{
					this.resultList = this.classList
				}
				this.getCheckList()
			},
			kwChange2(e) {
				this.index2 = e.target.value
			},
			onSubmit() {
				console.log(111, this.checkList)
				if (!this.maintainer) {
					return this.modal.show({
						type: 'error',
						content: '请输入操作员!'
					})
				}
				let list = this.checkList
				let obj = {
						equipmentSn: this.objMsg.deviceSn,
						tableNameCode: this.objMsg.query1,
						projectVoList: list,
						operator: this.maintainer,
						reviewer: this.reviewer,
						projectType:this.checkTypeList[this.index],
						dayOrNight:this.resultList[this.index2].value,
					}
				console.log(obj)
				this.save(obj)
			},
			save(obj) {
				this.$http.post('produce/mesMaintenanceRecordMain/addMesMaintenanceRecordItemForApp', obj).then(res => {
					if (res.data.success) {
						this.modal.show({
							type: 'success',
							content: res.data.message
						})
						// uni.navigateBack({
						// 	delta: 1
						// })
					} else {
						this.modal.show({
							type: 'error',
							content: res.data.message
						})
					}
				})
			},
		},
	}
</script>

<style lang="less">
	page {
		background-color: #f1f1f1;

		.fixed {
			position: fixed;
			z-index: 1;
			width: 100%;
			background-color: white;
			height: 100rpx;
			border-bottom: 1rpx solid #eee;

			.last {
				border-bottom: 1rpx solid #eee;
				position: relative;

				.icon {
					width: 30rpx;
					height: 29rpx;
					position: absolute;
					top: 36rpx;
					left: 60rpx;
				}

				input {
					width: 686rpx;
					height: 68rpx;
					background: #FFFFFF;
					border: 1px solid #D5D8DF;
					border-radius: 34px;
					padding-left: 79rpx;
				}
			}
		}

		.list {
			/deep/ .uni-input-input {
				border: 1px solid #d5d5d5;
				padding-right: 10rpx;
				border-radius: 10rpx;
				box-sizing: border-box;
			}

			input {
				font-size: 14px;
				font-weight: normal;
			}

			.card {
				margin: 30rpx;
				box-shadow: 0px 0px 5rpx 2rpx rgba(0, 0, 0, 0.1);
				border-radius: 10rpx;
				background-color: white;

				.top {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-weight: bold;
					padding: 20rpx 30rpx;

					.left {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #485A75;
						line-height: 50rpx;
					}

					.right {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #191919;
						line-height: 50rpx;
					}
				}

				.line {
					width: 100%;
					height: 10rpx;
					background: #F3F5F9;
				}

				.bottom {
					padding: 20rpx 30rpx;

					.box {
						display: flex;
						justify-content: space-between;
						padding: 20rpx 0;
						align-items: center;

						.lable {
							color: #485A75;
							font-size: 28rpx;
						}

						.content {
							width: 70%;
							text-align: right;
							color: #191919;
							font-weight: bold;
							word-break: break-all;
						}

						.shrink {
							height: 40rpx;
							overflow: hidden;
							white-space: nowrap;
							/*不换行*/
							text-overflow: ellipsis;
							/*超出部分文字以...显示*/
							font-weight: 400;
						}

						.unfold {
							text-align: left;
							font-weight: 400;
						}
					}
				}

				.btns {
					display: flex;
					justify-content: flex-end;
					align-items: center;
					padding: 0 20rpx;
					font-size: 25rpx;
					padding: 20rpx 30rpx;

					view {
						width: 180rpx;
						height: 64rpx;
						line-height: 50rpx;
						color: white;
						border-radius: 30rpx;
						padding: 10rpx 20rpx;
						text-align: center;
					}

					.btn1 {
						background-image: radial-gradient(circle, #3F55E9, #5F71ED, #7D8CF0);
					}

					.btn2 {
						background-image: radial-gradient(circle, #716BA9, #362D85, #57509A);
					}

					.btn3 {
						background-image: radial-gradient(circle, #354D9E, #354D9E, #697BB7);
					}
				}
			}
		}
	}

	.none .none1 {
		font-size: 30rpx;
		text-align: center;
		margin: 20rpx 0;
		color: #999999;
	}

	.none2 {
		font-size: 30rpx;
		text-align: center;
		margin: 20rpx 0;
		color: #999999;
	}

	// picker {
	// 	font-size: 15px !important;
	// 	font-weight: bold !important;
	// }
</style>
